#include "RPCClientPort.hpp"
#include "NodeClient.h"
#include <memory>
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/protocol/TProtocol.h>
#include <thrift/transport/TBufferTransports.h>
#include <thrift/transport/TSocket.h>
#include <thrift/transport/TTransport.h>

RPCClientPort::RPCClientPort(const std::string &ipaddr, long port)
    : Thrift::NodeClientClient(std::shared_ptr<
                               apache::thrift::protocol::TProtocol>(
          new apache::thrift::protocol::TBinaryProtocol(
              std::shared_ptr<apache::thrift::transport::TTransport>(
                  new apache::thrift::transport::TBufferedTransport(
                      std::shared_ptr<apache::thrift::transport::TTransport>(
                          new apache::thrift::transport::TSocket(ipaddr,
                                                                 port))))))) {}

void RPCClientPort::Boot() { getOutputProtocol()->getTransport()->open(); }

RPCClientPort::~RPCClientPort() {
  getOutputProtocol()->getTransport()->close();
}
